package com.yang;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class AddOneService extends Service {
    private AddOneThread addOneThread;

    private MyBinder myBinder;

    public AddOneService() {
        addOneThread = new AddOneThread();
    }

    @Override
    public IBinder onBind(Intent intent) {
        myBinder = new MyBinder();
        return myBinder;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        if (addOneThread != null) {
            addOneThread.endThread();
        }
        if (myBinder != null) {
            myBinder = null;
        }
        return super.onUnbind(intent);
    }

    class MyBinder extends Binder {
        public void startAddOne() {
            addOneThread.start();
        }
        public void pauseAddOne() {
            addOneThread.pauseAddOne();
        }
        public void continueAddOne() {
            addOneThread.continueAddOne();
        }
        public void endAddOne() {
            addOneThread.endThread();
        }
        public int getProgress() {
            return addOneThread.getCount();
        }
    }
}